package com.example.gkcircle;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.KeyEvent;

import com.example.gkcircle.utils.ActivityUtil;
import com.example.gkcircle.utils.MyAlertView;
import com.example.gkcircle.utils.MySVProgressHUD;

/**
 * Created by Jehu on 16/3/20.
 */
public abstract class BaseAppCompatActivity extends AppCompatActivity{


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        initView();
        initListener();
        setData();
        //添加Activity到栈
        ActivityUtil.getInstance().addActivity(this);
    }

    protected abstract void initView();

    protected abstract void initListener();

    protected abstract void setData();

    @Override
    protected void onStop() {
        super.onStop();
        if(MySVProgressHUD.mSVProgressHUD!=null){
            MySVProgressHUD.mSVProgressHUD=null;
        }
        if(MyAlertView.alertView!=null){
            MyAlertView.alertView=null;
        }
    }

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event)
    {
        if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0)
        {
            if(MySVProgressHUD.mSVProgressHUD!=null &&MySVProgressHUD.mSVProgressHUD.isShowing()){
                MySVProgressHUD.mSVProgressHUD.dismiss();
                return false;
            }
            if(MyAlertView.alertView!=null && MyAlertView.alertView.isShowing()){
                MyAlertView.alertView.dismiss();
                return false;
            }
        }

        return super.onKeyDown(keyCode, event);

    }

}
